library(tidyverse)
library(sf)
library(leaflet)
library(htmltools)
library(htmlwidgets)
## Reading layer `OGRGeoJSON' from data source `https://data.cityofchicago.org/api/geospatial/cauq-8yn6?method=export&format=GeoJSON' using driver `GeoJSON'
## Simple feature collection with 77 features and 9 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -87.94011 ymin: 41.64454 xmax: -87.52414 ymax: 42.02304
## geographic CRS: WGS 84
## Reading layer `OGRGeoJSON' from data source `https://data.cityofchicago.org/api/geospatial/ewy2-6yfk?method=export&format=GeoJSON' using driver `GeoJSON'
## Simple feature collection with 1 feature and 4 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -87.94011 ymin: 41.64454 xmax: -87.52414 ymax: 42.02304
## geographic CRS: WGS 84
commareaschi$describe <- 
  paste("Community Area Name:", commareaschi$community, "<br>", 
        "Community Area Number:", commareaschi$area_numbe, "<br>") %>% 
  lapply(htmltools::HTML)

Murals in Chicago

You can also embed plots, for example:

## Reading layer `OGRGeoJSON' from data source `https://data.cityofchicago.org/api/geospatial/we8h-apcf?method=export&format=GeoJSON' using driver `GeoJSON'
## replacing null geometries with empty geometries
## Simple feature collection with 356 features and 15 fields (with 5 geometries empty)
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: -87.83235 ymin: 41.68989 xmax: -87.55003 ymax: 42.01303
## geographic CRS: WGS 84

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

muralschi$describe <- 
  paste("Title:", muralschi$artwork_title, "<br>", 
        "Artist:", muralschi$artist_credit, "<br>",
        "Year:", muralschi$year_installed, "<br>",
        "Location:", muralschi$street_address, "<br>") %>% 
  lapply(htmltools::HTML)

muralschimap <- leaflet(muralschi) %>%
  addProviderTiles(providers$Stamen.Toner) %>%
  addCircles(fillColor = "tomato", color = "tomato", 
             stroke = FALSE, radius = 175,
              highlightOptions = highlightOptions(fillColor = "lawngreen", 
                                                  fillOpacity = 1),
              popup = ~describe) %>%
  addControl("Mural Locations in Chicago", position = "topright") %>%
  addControl('<a href="https://data.cityofchicago.org/Historic-Preservation/Mural-Registry/we8h-apcf">Data source</a>',
             position = "bottomleft") %>%
  setMaxBounds( lng1 = -87.940101,
                lat1 = 41.643919,
                lng2 = -87.523984,
                lat2 = 42.098388)
## Warning in validateCoords(lng, lat, funcName): Data contains 5 rows with either
## missing or invalid lat/lon values and will be ignored
muralschimap
muralschimap2 <- leaflet(cityboundarychi) %>%
  addProviderTiles(providers$Stamen.Toner) %>%
  addPolylines(data = cityboundarychi, stroke = T,
               color = "turquoise", 
               opacity = 1,
               weight = 3)  %>%
  addCircleMarkers(data= muralschi, 
             fill = TRUE,
             radius = 10,
             color = "lawngreen",
             fillOpacity = 0.5, 
             stroke = FALSE,
             label = ~ describe,
             clusterOptions = markerClusterOptions()) %>%
  addControl("Mural Locations in Chicago", position = "topright") %>%
  addControl('<a href="https://data.cityofchicago.org/Historic-Preservation/Mural-Registry/we8h-apcf">Data source</a>',
             position = "bottomleft") %>%
  setMaxBounds( lng1 = -87.940101,
                lat1 = 41.643919,
                lng2 = -87.523984,
                lat2 = 42.098388)
## Warning in validateCoords(lng, lat, funcName): Data contains 5 rows with either
## missing or invalid lat/lon values and will be ignored
muralschimap2
muralschimap3 <- leaflet(commareaschi) %>%
  addProviderTiles(providers$Stamen.Toner) %>%
  addPolygons(fillColor = "turquoise", stroke = FALSE,
              label = ~describe) %>%
    addPolylines(data = commareaschi, stroke = T, 
               color = "turquoise", 
               opacity = 1,
               weight = 1.25) %>%
addCircleMarkers(data= muralschi, 
             fill = TRUE,
             radius = 10,
             color = "tomato",
             fillOpacity = 0.5, 
             stroke = FALSE,
             label = ~ describe,
             clusterOptions = markerClusterOptions()) %>%
  addControl("Mural Locations in Chicago", position = "topright") %>%
  addControl('<a href="https://data.cityofchicago.org/Historic-Preservation/Mural-Registry/we8h-apcf">Data source</a>',
             position = "bottomleft") %>%
  setMaxBounds( lng1 = -87.940101,
                lat1 = 41.643919,
                lng2 = -87.523984,
                lat2 = 42.098388)
## Warning in validateCoords(lng, lat, funcName): Data contains 5 rows with either
## missing or invalid lat/lon values and will be ignored
muralschimap3

## TIF Districts in Chicago

## Reading layer `OGRGeoJSON' from data source `https://data.cityofchicago.org/api/geospatial/fz5x-7zak?method=export&format=GeoJSON' using driver `GeoJSON'
## Simple feature collection with 136 features and 17 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -87.79527 ymin: 41.64456 xmax: -87.52453 ymax: 42.01781
## geographic CRS: WGS 84

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

tifdistrictschi$describe <- 
  paste("Name of TIF:", tifdistrictschi$name, "<br>", 
        "TIF Use", tifdistrictschi$use, "<br>",
        "Community Areas for TIF:", tifdistrictschi$comm_area, "<br>") %>% 
  lapply(htmltools::HTML)

tifdistrictschimap <- leaflet(tifdistrictschi) %>%
  addProviderTiles(providers$Stamen.Toner) %>%
  addPolygons(fillColor = "blue", stroke = FALSE,
              highlightOptions = highlightOptions(fillColor = "orange", 
                                                  fillOpacity = 1),
              label = ~describe) %>%
  addControl("Tax Increment Financing (TIF) Districts in Chicago", position = "topright") %>%
  addControl('<a href="https://data.cityofchicago.org/Community-Economic-Development/Boundaries-Tax-Increment-Financing-Districts/fz5x-7zak#revert">Data source</a>',
             position = "bottomleft") %>%
  setMaxBounds( lng1 = -87.805388,
                lat1 = 41.609952,
                lng2 = -87.461107,
                lat2 = 42.027398)

tifdistrictschimap
tifdistrictschimap2 <- leaflet(commareaschi) %>%
  addProviderTiles(providers$Stamen.Toner) %>%
  addPolygons(fillColor = "orange", stroke = FALSE,
              label = ~describe) %>%
    addPolylines(data = commareaschi, stroke = T, 
               color = "orange", 
               opacity = 1,
               weight = 1.5) %>%
   addPolygons(data = tifdistrictschi,
               fillColor = "blue", fillOpacity = 0.5, stroke = FALSE,
              highlightOptions = highlightOptions(fillColor = "blue", 
                                                  fillOpacity = 3),
              label = ~describe) %>%
  addControl("Tax Increment Financing (TIF) Districts in Chicago", position = "topright") %>%
  addControl('<a href="https://data.cityofchicago.org/Community-Economic-Development/Boundaries-Tax-Increment-Financing-Districts/fz5x-7zak#revert">Data source</a>',
             position = "bottomleft") %>%
  setMaxBounds( lng1 = -87.805388,
                lat1 = 41.609952,
                lng2 = -87.461107,
                lat2 = 42.027398)

tifdistrictschimap2
saveWidget(muralschimap, file = "chicagomurals.html")
saveWidget(tifdistrictschimap, file = "chicagotifs.html")
saveWidget(muralschimap2, file = "chicagomurals2.html")
saveWidget(tifdistrictschimap2, file = "chicagotifs2.html")
saveWidget(muralschimap3, file = "chicagomurals3.html")